<?php
class Jmb_Model_Index extends Jmb_Model_Base{

    /**
     * 都道府県ごとの店舗件数保持用データに変換
     * @param $prefCntList
     * @return　変換後データ
     */
    public function convertData($prefCntList)
    {
		$arrPrefCnt = array();
        $prefCd = null;
    	$recCnt = null;
        
		for ($count = 1; $count <= 47; $count++)
		{
			$arrPrefCnt[$count]['TENPO_CNT'] = 0;
		}
    	
        foreach ($prefCntList as $prefCntData)
        {
            $prefCd = intval($prefCntData['M43_TODOUFUKEN_CD']);
            $recCnt = intval($prefCntData['REC_CNT']);

            $arrPrefCnt[$prefCd]['TENPO_CNT'] = $recCnt;
        }
        
        return $arrPrefCnt;
    }
    
	/**
     * マイレージトップsql文生成
     * @param $params
     * @param $db_params
     * @return sql文
     */
    protected function generateSql($params, &$db_params)
    {

$sql = <<< DOC_END

SELECT
        M43_TODOUFUKEN_CD
        ,NVL(REC_CNT, 0) AS REC_CNT
    FROM
        M43TODOUFUKEN A
        ,
        (
            SELECT
                    M05_TENPO_TODOUFUKEN_CD
                    ,COUNT(*) AS REC_CNT
                FROM
                    M05TENPO_INFO A
                WHERE
					M05_TOKUCHO12 = '1'
                GROUP BY
                    M05_TENPO_TODOUFUKEN_CD
        )
    WHERE
        M43_TODOUFUKEN_CD = M05_TENPO_TODOUFUKEN_CD

DOC_END;

		return $sql;
    }
}
?>
